const express = require('express')
const app = express()
const cors = require('cors')
const studentRoutes = require('./routes')

// 使用中间件
app.use(cors())
app.use(express.json())

// 使用路由
app.use('/api', studentRoutes)

// 全局错误处理中间件
app.use((err, req, res, next) => {
  console.error(err.stack)
  res.status(500).json({ message: 'Internal Server Error' })
})

// 启动服务
const PORT = process.env.PORT || 5000
app.listen(PORT, () => console.log(`Server running on port ${PORT}`))
